package com.keyroy.game.puzzle_rpg.models.render;

import com.keyroy.game.puzzle_rpg.models.interfaces.SWTDrawable;
import com.keyroy.game.puzzle_rpg.models.world.Map;
import com.keyroy.game.puzzle_rpg.models.world.MapNode;

public class MapRender extends SWTDrawable {
	private Map map;
	private Object mapImage;

	public MapRender(Map map) {
		this.map = map;
	}

	@Override
	protected void onDraw() {
		if (map != null) {
			if (mapImage == null) {
				mapImage = getImage(map.icon);
			}
			drawImage(mapImage, 0, 0);

			for (int i = 0; i < map.mapNodes.size(); i++) {
				MapNode mapNode = map.mapNodes.get(i);
				if (mapNode.getImage() == null && mapNode.icon != null) {
					mapNode.setImage(getImage(mapNode.icon));
				}

				if (mapNode.getImage() != null) {
					drawImage(mapNode.getImage(), mapNode.x, mapNode.y);
				}
			}

		}

	}

}
